﻿namespace WMS6.SQLServerDAL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;

    public class InvoicePaymentDetailDA : IInvoicePaymentDetailDA
    {
        private string CREATED_BY = "@CREATED_BY";
        private string INVOICE_ID = "@INVOICE_ID";
        private string LINE_ID = "@LINE_ID";
        private string PAY_AMOUNT = "@PAY_AMOUNT";
        private string REMARK = "@REMARK";
        private string SEQ_NO = "@SEQ_NO";
        private string SQL_CHECK_INVOICE_PAYMENT_DETAIL_ID_UNIQUE = " SELECT COUNT(1) FROM @_@INVOICE_PAYMENT_DETAIL WHERE INVOICE_ID = @INVOICE_ID AND LINE_ID = @LINE_ID AND SEQ_NO = @SEQ_NO ";
        private string SQL_DELETE_INVOICE_PAYMENT_DETAIL = " DELETE FROM @_@INVOICE_PAYMENT_DETAIL WHERE INVOICE_ID = @INVOICE_ID AND LINE_ID = @LINE_ID AND SEQ_NO = @SEQ_NO ";
        private string SQL_INSERT_INVOICE_PAYMENT_DETAIL = " INSERT INTO @_@INVOICE_PAYMENT_DETAIL ( WH_ID, INVOICE_ID, LINE_ID, SEQ_NO, PAY_AMOUNT, REMARK, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE) VALUES ( @WH_ID, @INVOICE_ID, @LINE_ID, @SEQ_NO, @PAY_AMOUNT, @REMARK, @CREATED_BY, GETDATE(), @UPDATED_BY, GETDATE() )  ";
        private string SQL_SELECT_ALL_INVOICE_PAYMENT_DETAIL = " SELECT  ROWID, WH_ID, INVOICE_ID, LINE_ID, SEQ_NO, PAY_AMOUNT, REMARK, TS, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE  FROM  @_@INVOICE_PAYMENT_DETAIL ";
        private string SQL_SELECT_ALL_INVOICE_PAYMENT_DETAIL_ST = "SELECT ID.STATEMENT_ID,IPD.* FROM @_@INVOICE_PAYMENT_DETAIL IPD LEFT JOIN @_@INVOICE I ON I.INVOICE_ID = IPD.INVOICE_ID LEFT JOIN @_@INVOICE_DETAIL ID ON ID.INVOICE_ID = I.INVOICE_ID AND ID.LINE_ID = IPD.LINE_ID";
        private string SQL_SELECT_INVOICE_PAYMENT_DETAIL_MAX_SEQ = " SELECT ISNULL(MAX(SEQ_NO),0) AS SEQ_NO FROM @_@INVOICE_PAYMENT_DETAIL WHERE INVOICE_ID = @INVOICE_ID ";
        private string SQL_UPDATE_INVOICE_PAYMENT_DETAIL = " UPDATE @_@INVOICE_PAYMENT_DETAIL SET WH_ID = @WH_ID, PAY_AMOUNT = @PAY_AMOUNT, REMARK = @REMARK, UPDATED_BY = @UPDATED_BY, UPDATED_DATE = GETDATE() WHERE INVOICE_ID = @INVOICE_ID AND LINE_ID = @LINE_ID AND SEQ_NO = @SEQ_NO  ";
        private string TS = "@TS";
        private string UPDATED_BY = "@UPDATED_BY";
        private string WH_ID = "@WH_ID";

        public bool CheckInvoicePaymentDetailIDUnique(string invoiceID, string lineID, string seqNo, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INVOICE_ID", invoiceID), new SqlParameter("@LINE_ID", lineID), new SqlParameter("@SEQ_NO", seqNo) };
            return (DBHelper.ExecuteScalar(CommandType.Text, this.SQL_CHECK_INVOICE_PAYMENT_DETAIL_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public bool CheckInvoicePaymentDetailIDUnique(DataBase dataBase, DbTransaction tran, string invoiceID, string lineID, string seqNo, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INVOICE_ID", invoiceID), new SqlParameter("@LINE_ID", lineID), new SqlParameter("@SEQ_NO", seqNo) };
            return (dataBase.ExecuteScalar(tran, CommandType.Text, this.SQL_CHECK_INVOICE_PAYMENT_DETAIL_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public int DeleteInvoicePaymentDetail(List<string> invoiceID, List<string> lineID, List<string> seqNo, List<string> whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < invoiceID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INVOICE_ID", invoiceID), new SqlParameter("@LINE_ID", lineID), new SqlParameter("@SEQ_NO", seqNo) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_INVOICE_PAYMENT_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                conn.Close();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int DeleteInvoicePaymentDetail(DataBase dataBase, DbTransaction tran, List<string> invoiceID, List<string> lineID, List<string> seqNo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < invoiceID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INVOICE_ID", invoiceID), new SqlParameter("@LINE_ID", lineID), new SqlParameter("@SEQ_NO", seqNo) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_INVOICE_PAYMENT_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public DataSet GetAllInvoicePaymentDetail(string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_INVOICE_PAYMENT_DETAIL.Replace("@_@", whLoginID);
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetAllInvoicePaymentDetail(DataBase dataBase, DbTransaction tran, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_INVOICE_PAYMENT_DETAIL.Replace("@_@", whLoginID);
            return dataBase.ExecuteDataSet(tran, CommandType.Text, sql);
        }

        public InvoicePaymentDetailInfo GetInvoicePaymentDetailByID(string invoiceID, string lineID, string seqNo, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_INVOICE_PAYMENT_DETAIL_ST.Replace("@_@", whLoginID) + " WHERE IPD.INVOICE_ID = @INVOICE_ID AND LINE_ID = @LINE_ID AND SEQ_NO = @SEQ_NO  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INVOICE_ID", invoiceID), new SqlParameter("@LINE_ID", lineID), new SqlParameter("@SEQ_NO", seqNo) };
            InvoicePaymentDetailInfo invoicePaymentDetailInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                if (reader.Read())
                {
                    invoicePaymentDetailInfo = new InvoicePaymentDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["INVOICE_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, (reader["SEQ_NO"].ToString() != "") ? int.Parse(reader["SEQ_NO"].ToString()) : 0, (reader["PAY_AMOUNT"].ToString() != "") ? decimal.Parse(reader["PAY_AMOUNT"].ToString()) : 0M, reader["REMARK"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime(), reader["STATEMENT_ID"].ToString());
                }
            }
            return invoicePaymentDetailInfo;
        }

        public InvoicePaymentDetailInfo GetInvoicePaymentDetailByID(DataBase dataBase, DbTransaction tran, string invoiceID, string lineID, string seqNo, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_INVOICE_PAYMENT_DETAIL_ST.Replace("@_@", whLoginID) + " WHERE IPD.INVOICE_ID = @INVOICE_ID AND LINE_ID = @LINE_ID AND SEQ_NO = @SEQ_NO  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INVOICE_ID", invoiceID), new SqlParameter("@LINE_ID", lineID), new SqlParameter("@SEQ_NO", seqNo) };
            InvoicePaymentDetailInfo invoicePaymentDetailInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            if (reader.Read())
            {
                invoicePaymentDetailInfo = new InvoicePaymentDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["INVOICE_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, (reader["SEQ_NO"].ToString() != "") ? int.Parse(reader["SEQ_NO"].ToString()) : 0, (reader["PAY_AMOUNT"].ToString() != "") ? decimal.Parse(reader["PAY_AMOUNT"].ToString()) : 0M, reader["REMARK"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime(), reader["STATEMENT_ID"].ToString());
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return invoicePaymentDetailInfo;
        }

        public DataSet GetInvoicePaymentDetailByQueryList(List<string> sqlWhere, InvoicePaymentDetailQueryEntity invoicepaymentdetailQuery, string whLoginID)
        {
            string temp = this.SQL_SELECT_ALL_INVOICE_PAYMENT_DETAIL.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!invoicepaymentdetailQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, invoicepaymentdetailQuery.CurrentPage, invoicepaymentdetailQuery.PageSize, invoicepaymentdetailQuery.SortField, invoicepaymentdetailQuery.SortDirection);
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, temp);
        }

        public DataSet GetInvoicePaymentDetailByQueryList(DataBase dataBase, DbTransaction tran, List<string> sqlWhere, InvoicePaymentDetailQueryEntity invoicepaymentdetailQuery, string whLoginID)
        {
            string temp = this.SQL_SELECT_ALL_INVOICE_PAYMENT_DETAIL.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            temp = PagingHelper.GetPagingSQL(temp, invoicepaymentdetailQuery.CurrentPage, invoicepaymentdetailQuery.PageSize, invoicepaymentdetailQuery.SortField, invoicepaymentdetailQuery.SortDirection);
            return dataBase.ExecuteDataSet(tran, CommandType.Text, temp);
        }

        public List<InvoicePaymentDetailInfo> GetInvoicePaymentDetailListByID(string invoiceID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_INVOICE_PAYMENT_DETAIL_ST.Replace("@_@", whLoginID) + " WHERE IPD.INVOICE_ID = @INVOICE_ID ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INVOICE_ID", invoiceID) };
            InvoicePaymentDetailInfo invoicePaymentDetailInfo = null;
            List<InvoicePaymentDetailInfo> invoicePaymentDetailInfos = new List<InvoicePaymentDetailInfo>();
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                while (reader.Read())
                {
                    DateTime CS00002;
                    invoicePaymentDetailInfo = new InvoicePaymentDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["INVOICE_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, (reader["SEQ_NO"].ToString() != "") ? int.Parse(reader["SEQ_NO"].ToString()) : 0, (reader["PAY_AMOUNT"].ToString() != "") ? decimal.Parse(reader["PAY_AMOUNT"].ToString()) : 0M, reader["REMARK"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["STATEMENT_ID"].ToString());
                    invoicePaymentDetailInfos.Add(invoicePaymentDetailInfo);
                }
            }
            return invoicePaymentDetailInfos;
        }

        public List<InvoicePaymentDetailInfo> GetInvoicePaymentDetailListByID(DataBase dataBase, DbTransaction tran, string invoiceID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_INVOICE_PAYMENT_DETAIL_ST.Replace("@_@", whLoginID) + " WHERE IPD.INVOICE_ID = @INVOICE_ID";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INVOICE_ID", invoiceID) };
            InvoicePaymentDetailInfo invoicePaymentDetailInfo = null;
            List<InvoicePaymentDetailInfo> invoicePaymentDetailInfos = new List<InvoicePaymentDetailInfo>();
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            while (reader.Read())
            {
                DateTime CS00002;
                invoicePaymentDetailInfo = new InvoicePaymentDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["INVOICE_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, (reader["SEQ_NO"].ToString() != "") ? int.Parse(reader["SEQ_NO"].ToString()) : 0, (reader["PAY_AMOUNT"].ToString() != "") ? decimal.Parse(reader["PAY_AMOUNT"].ToString()) : 0M, reader["REMARK"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["STATEMENT_ID"].ToString());
                invoicePaymentDetailInfos.Add(invoicePaymentDetailInfo);
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return invoicePaymentDetailInfos;
        }

        public string GetInvoicePaymentDetailMaxSeq(string invoiceID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INVOICE_ID", invoiceID) };
            return DBHelper.ExecuteScalar(CommandType.Text, this.SQL_SELECT_INVOICE_PAYMENT_DETAIL_MAX_SEQ.Replace("@_@", whLoginID), paras).ToString();
        }

        public string GetInvoicePaymentDetailMaxSeq(DataBase dataBase, DbTransaction tran, string invoiceID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@INVOICE_ID", invoiceID) };
            return dataBase.ExecuteScalar(tran, CommandType.Text, this.SQL_SELECT_INVOICE_PAYMENT_DETAIL_MAX_SEQ.Replace("@_@", whLoginID), paras).ToString();
        }

        public int InsertInvoicePaymentDetail(InvoicePaymentDetailInfo invoicePaymentDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    invoicePaymentDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_InvoicePaymentDetail_Parameters(invoicePaymentDetailInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_INVOICE_PAYMENT_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                conn.Close();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int InsertInvoicePaymentDetail(DataBase dataBase, DbTransaction tran, InvoicePaymentDetailInfo invoicePaymentDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    invoicePaymentDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_InvoicePaymentDetail_Parameters(invoicePaymentDetailInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_INVOICE_PAYMENT_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        private SqlParameter[] Set_InvoicePaymentDetail_Parameters(InvoicePaymentDetailInfo invoicePaymentDetailInfo)
        {
            SqlParameter[] paramArray = new SqlParameter[] { new SqlParameter(this.WH_ID, SqlDbType.VarChar, 30), new SqlParameter(this.INVOICE_ID, SqlDbType.VarChar, 30), new SqlParameter(this.LINE_ID, SqlDbType.Int, 4), new SqlParameter(this.SEQ_NO, SqlDbType.Int, 4), new SqlParameter(this.PAY_AMOUNT, SqlDbType.Decimal, 13), new SqlParameter(this.REMARK, SqlDbType.VarChar, 300), new SqlParameter(this.CREATED_BY, SqlDbType.VarChar, 20), new SqlParameter(this.UPDATED_BY, SqlDbType.VarChar, 20) };
            if (!string.IsNullOrEmpty(invoicePaymentDetailInfo.WhID))
            {
                paramArray[0].Value = invoicePaymentDetailInfo.WhID;
            }
            else
            {
                paramArray[0].Value = DBNull.Value;
            }
            paramArray[1].Value = invoicePaymentDetailInfo.InvoiceID;
            paramArray[2].Value = invoicePaymentDetailInfo.LineID;
            paramArray[3].Value = invoicePaymentDetailInfo.SeqNo;
            paramArray[4].Value = invoicePaymentDetailInfo.PayAmount;
            if (!string.IsNullOrEmpty(invoicePaymentDetailInfo.Remark))
            {
                paramArray[5].Value = invoicePaymentDetailInfo.Remark;
            }
            else
            {
                paramArray[5].Value = DBNull.Value;
            }
            paramArray[6].Value = invoicePaymentDetailInfo.CreatedBy;
            paramArray[7].Value = invoicePaymentDetailInfo.UpdatedBy;
            return paramArray;
        }

        public int UpdateInvoicePaymentDetail(InvoicePaymentDetailInfo invoicePaymentDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    invoicePaymentDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_InvoicePaymentDetail_Parameters(invoicePaymentDetailInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_INVOICE_PAYMENT_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                conn.Close();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int UpdateInvoicePaymentDetail(DataBase dataBase, DbTransaction tran, InvoicePaymentDetailInfo invoicePaymentDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    invoicePaymentDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_InvoicePaymentDetail_Parameters(invoicePaymentDetailInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_INVOICE_PAYMENT_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }
    }
}

